package org.skydiveapplibrary.data;

import java.util.ArrayList;
import java.util.List;

import org.skydiveapplibrary.R;

public enum AltitudeUnit
{
	Feet (R.string.altitude_unit_feet),
	Meters (R.string.altitude_unit_meters);
	
	// conversion ratios
	private static final float FEET_TO_METERS = new Float(0.3048);
	private static final float FEET_TO_MILES = new Float(5280);
	private static final float METERS_TO_KILOMETERS = new Float(1000);
	
	private int resourceId;
	
	AltitudeUnit(int resourceId)
	{
		this.resourceId = resourceId;
	}
	
	public int getResourceId()
	{
		return resourceId; 
	}
	
	public static List<AltitudeUnit> getItems()
	{
		List<AltitudeUnit> units = new ArrayList<AltitudeUnit>();
		for (AltitudeUnit unit: AltitudeUnit.values())
		{
			units.add(unit);
		}
		
		return units;
	}
	
	public static float convert(float value, AltitudeUnit from, AltitudeUnit to)
	{
		float result = value;
		if (from == AltitudeUnit.Feet && to == AltitudeUnit.Meters)
		{
			return value * FEET_TO_METERS;
		}
		else if (from == AltitudeUnit.Meters && to == AltitudeUnit.Feet)
		{
			return value / FEET_TO_METERS;
		}
		
		return result;
	}
	
	public static float convertToDistance(float value, AltitudeUnit unit)
	{
		if (unit == AltitudeUnit.Feet)
		{
			return value / FEET_TO_MILES;
		}
		else
		{
			return value / METERS_TO_KILOMETERS;
		}
	}
}
